package com.itheima.tanhua.admin.controller;


import com.itheima.commons.utils.CheckCodeUtil;
import com.itheima.tanhua.admin.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/system/users")
public class SystemController {
    @Autowired
    private SystemService systemService;

    /*用户登陆验证码图片*/

    @GetMapping("/verification")
    public ResponseEntity verification(String uuid, HttpServletResponse response) throws IOException {
        systemService.code(uuid, response);
        return ResponseEntity.ok(null);
    }

    /*用户登陆*/
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map<String, String> map) {
        String username = map.get("username");
        String password = map.get("password");
        String verificationCode = map.get("verificationCode");
        String uuid = map.get("uuid");
        Map token = systemService.login(username, password, verificationCode, uuid);
        return ResponseEntity.ok(token);
    }

    /*用户登出*/
    @PostMapping("/logout")
    public ResponseEntity logout() {
        systemService.logout();
        return ResponseEntity.ok(null);
    }

    /*用户基本信息*/
    @PostMapping("/profile")
    public ResponseEntity profile() {
        return ResponseEntity.ok(systemService.find());
    }
}
